
package com.wyzz.hr.bo.impl;

import java.util.List;
import org.hibernate.FetchMode;
import org.hibernate.criterion.*;

import com.wyzz.hr.bo.IInmatchBO;
import com.wyzz.hr.dao.IInmatchDAO;
import com.wyzz.hr.pojo.Inmatch;
import com.wyzz.hr.pojo.InmatchBasic;
import com.wyzz.hr.pojo.InmatchModel;


public class InmatchBOImpl implements IInmatchBO {

	public InmatchBOImpl() {
	}

	public IInmatchDAO getDao() {
		return dao;
	}

	public void setDao(IInmatchDAO dao) {
		this.dao = dao;
	}

	public void initInmatchMaps(List imList) {
		for (int i = 0; i < imList.size(); i++)
			((Inmatch) imList.get(i)).setAllMaps();

	}

	public List getInmatchList(InmatchModel inmatchModel) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Inmatch.class);
		detachedCriteria.setFetchMode(Inmatch.PROP_IM_IMB, FetchMode.JOIN);
		detachedCriteria
				.add(Restrictions.eq(Inmatch.PROP_IM_IMM, inmatchModel));
		detachedCriteria.addOrder(Order.asc(Inmatch.PROP_IM_SORT_ID));
		List result = dao.findByCriteria(detachedCriteria);
		if (result != null && result.size() > 0)
			return result;
		else
			return null;
	}

	public List getInmatchListByImb(String imbId) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Inmatch.class);
		detachedCriteria.add(Restrictions.eq(Inmatch.PROP_IM_IMB,
				new InmatchBasic(imbId)));
		List result = dao.findByCriteria(detachedCriteria);
		return result;
	}

	public List getInputList(InmatchModel inmatchModel) {
		DetachedCriteria detachedCriteria = DetachedCriteria
				.forClass(com.wyzz.hr.pojo.Inmatch.class);
		detachedCriteria.setFetchMode(Inmatch.PROP_IM_IMB, FetchMode.JOIN);
		detachedCriteria
				.add(Restrictions.eq(Inmatch.PROP_IM_IMM, inmatchModel));
		detachedCriteria.add(Restrictions.eq(Inmatch.PROP_IM_IS_INPUT, Integer
				.valueOf(1)));
		detachedCriteria.addOrder(Order.asc(Inmatch.PROP_IM_SORT_ID));
		List result = dao.findByCriteria(detachedCriteria);
		if (result != null && result.size() > 0)
			return result;
		else
			return null;
	}

	private IInmatchDAO dao;
}
